xquery version "1.0";
<catalog>
  {
    for $b in doc("book_p2.xml")/catalog/book
    let $a := $b/author[first="Tim"]
    where $b/author/first = $a/first
    order by $b/title
    return 
		<book>
			{$b/title}
			{$a}
		</book>
  }
</catalog>
